'use strict';

var express = require('express');
var router = express.Router();
var columnModule = require('../../modules/columns_module');


router.post('/:id', function(req, res, next){
  columnModule.addColumn(req.body)
  .then(function(data){
    res.json({
      code: 0,
      message: 'success',
      data: data
    });
  }, function(error){
    res.json({
      message: error.message
    });
  });
});


router.get('/:id', function(req, res, next){
  columnModule.getColumn(req.params.id)
  .then(function(data){
    res.json({
      code: 0,
      message: 'success',
      data: data
    });
  },function(error){
    res.json({
      message: error.message
    });
  });
});


router.put('/:id', function(req, res, next){
  columnModule.updateColumn(req.params.id, req.body)
  .then(function(success){
    res.json({
      code: 0,
      message: 'success'
    });
  }, function(error){
    res.json({
      message: error.message
    });
  });
});


router.delete('/:id', function(req, res, next){
  columnModule.deleteColumn(req.params.id)
  .then(function(success){
    res.json({
      code: 0,
      message: 'success'
    });
  }, function(error){
    res.json({
      message: error.message
    });
  });
});


module.exports = router;